package com.example.function.integration.jrss;

import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.springframework.stereotype.Component;

@Component
public class JrssBucketConfig {

    // ------------------------------------------------------bucket常量配置
    public static int shardNum = 10;
    /*
    @Value("${shardNum:10}")
    public void setShardNum(int shardNum) {
        this.shardNum = shardNum;
    }

    // ------------------------------------------------------bucket名称配置
    // 电子合同专用bucket
    @Value("${jrss.eleContractBucket}")
    public String eleContractBucket;

    //运营报告图片bucket
    @Value("${jrss.operationReportBucket}")
    public String operationReportBucket;
    */

    // ------------------------------------------------------bucket公共方法

    /**
     * hash路由bucket名称方法
     *
     * @param bucketName
     * @param fileKey
     * @return
     */
    public static String hashRoute(String bucketName, String fileKey) {
        HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
        hashCodeBuilder.append(fileKey);
        int number = hashCodeBuilder.toHashCode();
        return bucketName + "-" + Math.abs(number % shardNum);
    }

}